<?php

namespace App\Services;

use App\Model\Company;
use App\Model\Comcheck;
use App\User;
use Illuminate\Support\Facades\Storage;
use File;

class WordcheckdataClass {

	//通知单
	public function createNotice ( Company $company, Comcheck $checkinfo, $checkdetail, $address, $checkUser,$manager) {
		$year = date('Y',strtotime($checkinfo->created));
		$month = date('m',strtotime($checkinfo->created));
		$day = date('d',strtotime($checkinfo->created));
		$hour = date('H', strtotime($checkinfo->created));
		$startDate = date('Y年m月d日',strtotime($checkinfo->created));
		$againDate = date('Y年m月d日',strtotime($checkinfo->againDate));
		$fireinfo = [];
		$nofireinfo = [];
		foreach ($checkdetail as $k => $v)
		{
			if($v->type == 1) {
				$fireinfo[] = $v;
			}
			if($v->type == 2) {
				$nofireinfo[] = $v;
			}
		}
		$data['comName'] = $company->comName;
		$data['address'] = $address['city'] . $address['district'] . $address['street'] . $company->address;
		$data['year'] = $year;
		$data['month'] = $month;
		$data['day'] = $day;
		$data['startHour'] = $hour;
		$data['startDate'] = $startDate;
		$data['againDate'] = $againDate;
		$data['endHour'] = date('H', strtotime('+1 hour',strtotime($checkinfo->created)));
		$data['accompany'] = $company->accompany;
		$data['leader'] = $company->leader;
		$data['leaderPhone'] = $company->leaderPhone;
		if(!empty($manager)) {
			$data['manager'] = $manager->name;
			$data['managerPhone'] = $manager->phone;
		} else {
			$data['manager'] = "";
			$data['managerPhone'] = "";
		}
		$data['checkUser'] = $checkUser->name;
		$data['serviceUser'] = $company->service;
		$i = 0;
		$j = 0;
		$fireArchives = "";
		$fireWork = "";
		$productArchives = "";
		$productWork = "";
		foreach ( $fireinfo as $k => $v ) {
			if($v->status==1) {
				$i++;
				if(!empty($v->entryId)) {
					$tmpContent = $v->content;
					$tmpContent = str_replace(";", ",", trim($tmpContent,";"));
					$fireArchives .= '（' . $i . '）' . trim($v->necontent . ',' . $tmpContent, ',') . '；<w:br />';
				} else {
					$fireArchives .= '（' . $i . '）' . $v->contentexist . '；<w:br />';
				}
				
			}
		}
		foreach ( $fireinfo as $k => $v ) {
			if($v->status==2) {
				$i++;
				if(!empty($v->entryId)) {
					$tmpContent = $v->content;
					$tmpContent = str_replace(";", ",", trim($tmpContent,";"));
					$fireWork .= '（' . $i . '）' . trim($v->necontent . ',' . $tmpContent, ',') . '；<w:br />';
				} else {
					$fireWork .= '（' . $i . '）' . $v->contentexist . '；<w:br />';
				}
				
			}
		}
		$fireArchives = mb_substr($fireArchives,0,-8,'utf-8');
		$fireWork = mb_substr($fireWork,0,-8,'utf-8');	
		if(!empty($fireArchives)&&!empty($fireWork)) {
			$fireWork = mb_substr($fireWork,0,-1,'utf-8')."。";	
		} else if(!empty($fireArchives)) {
			$fireArchives = mb_substr($fireArchives,0,-1,'utf-8')."。";
			$fireWork = '无';
		} else if(!empty($fireWork)) {
			$fireWork = mb_substr($fireWork,0,-1,'utf-8')."。";
			$fireArchives = '无';
		}

		foreach ( $nofireinfo as $k => $v ) {
			if($company->enterprise == 3) {
				$j = $i;
			}
			if($v->status==1) {
				$j++;
				
				if(!empty($v->entryId)) {
					$tmpContent = $v->content;
					$tmpContent = str_replace(";", ",", trim($tmpContent,";"));
					$productArchives .= '（' . $j . '）' . trim($v->necontent . ',' . $tmpContent, ',') . '；<w:br />';
				} else {
					$productArchives .= '（' . $j . '）' . $v->contentexist . '；<w:br />';
				}
			}
		}

		foreach ( $nofireinfo as $k => $v ) {
			if($company->enterprise == 3) {
				$j = $i;
			}
			if($v->status==2) {
				$j++;
				if(!empty($v->entryId)) {
					$tmpContent = $v->content;
					$tmpContent = str_replace(";", ",", trim($tmpContent,";"));
					$productWork .= '（' . $j . '）' . trim($v->necontent . ',' . $tmpContent, ',') . '；<w:br />';
				} else {
					$productWork .= '（' . $j . '）' . $v->contentexist . '；<w:br />';
				}
				
			}
		}
		$productArchives = mb_substr($productArchives,0,-8,'utf-8');
		$productWork = mb_substr($productWork,0,-8,'utf-8');
		if(!empty($productArchives)&&!empty($productWork)) {
			$productWork = mb_substr($productWork,0,-1,'utf-8')."。";
		} else if(!empty($productArchives)) {
			$productArchives = mb_substr($productArchives,0,-1,'utf-8')."。";
			$productWork = '无';
		} else if(!empty($productWork)) {
			$productWork = mb_substr($productWork,0,-1,'utf-8')."。";
			$productArchives = '无';
		}
		$comsignature = '.' . $checkinfo->comsignature;
		$usersignature = $checkinfo->usersignature;
        if($comsignature && file_exists($comsignature)){
            $imgData['comsignature'] = ['path' => $comsignature,'width'=>120,'height'=>80];
        }else{
            $imgData['comsignature'] = ['path' => '.','width'=>120,'height'=>80];
        }
        if($usersignature && file_exists($usersignature)){
            $imgData['usersignature'] = ['path' => $usersignature,'width'=>120,'height'=>80];
        }else{
            $imgData['usersignature'] = ['path' => '.','width'=>120,'height'=>80];
        }

		if(!empty($checkUser)) {
			$data['userPhone'] = $checkUser->phone;
		} else {
			$data['userPhone'] = "";
		}
		$wordData['data'] = $data;
		$wordData['imgData'] = $imgData;
		$wordData['fire']['manageArchive'] = $fireArchives;
		$wordData['fire']['work'] = $fireWork;
		$wordData['product']['manageArchive'] = $productArchives;
		$wordData['product']['work'] = $productWork;
		return $wordData;
	}

	//检查报告
	public function createExport ( Company $company, Comcheck $checkinfo,User $user,$checkdetail, $safeoffer, $address ) {
		$year = date('Y',strtotime($checkinfo->created));
		$month = date('m',strtotime($checkinfo->created));
		$day = date('d',strtotime($checkinfo->created));
		$report = [
			'nofire1' => 0,
			'nofire2' => 0,
			'nofire3' => 0,
			'nofire4' => 0,
			'fire1'   => 0,
			'fire2'   => 0,
			'fire3'   => 0,
			'fire4'   => 0,
		];
		foreach ( $checkdetail as $k => $v ) {
			if ( $v->type == 1 ) {
				switch ( $v->status ) {
					case '1':
						$report['fire1'] += 1;
						break;
					case '2':
						$report['fire2'] += 1;
						break;
					case '3':
						$report['fire3'] += 1;
						break;
					case '4':
						$report['fire4'] += 1;
						break;
					default:
						# code...
						break;
				}
			}
			if ( $v->type == 2 ) {
				switch ( $v->status ) {
					case '1':
						$report['nofire1'] += 1;
						break;
					case '2':
						$report['nofire2'] += 1;
						break;
					case '3':
						$report['nofire3'] += 1;
						break;
					case '4':
						$report['nofire4'] += 1;
						break;
					default:
						# code...
						break;
				}
			}
		}
		$report['comName'] = $company->comName;
		$report['address'] = $address['city'] . $address['district'] . $address['street'] . $company->address;
		$report['street'] = $address['street'];
		$report['space'] = $company->space;
		$report['workersNum'] = $company->workersNum;
		$report['leader'] = $company->leader;
		$report['leaderPhone'] = $company->leaderPhone;
		$report['safename'] = isset($safeoffer->name)?$safeoffer->name:"";
		$report['safephone'] = isset($safeoffer->phone)?$safeoffer->phone:"";
		$report['count1'] = $report['fire1'] + $report['nofire1'];
		$report['count2'] = $report['fire2'] + $report['nofire2'];
		$report['count3'] = $report['fire3'] + $report['nofire3'];
		$report['count4'] = $report['fire4'] + $report['nofire4'];
		$report['firecount'] = $report['fire1'] + $report['fire2'] + $report['fire3'] + $report['fire4'];
		$report['nofirecount'] = $report['nofire1'] + $report['nofire2'] + $report['nofire3'] + $report['nofire4'];
		$report['total'] = $report['count1'] + $report['count2'] + $report['count3'] + $report['count4'];
		$report['year'] = $year;
		$report['month'] = $month;
		$report['day'] = $day;
		$report['accompany'] = $company->accompany;
		$report['day'] = $day;
		$report['username'] = $user->name;
		$photoPath = '.' . $company->photo;
		$mapingPath = '.' . $checkinfo->mapimg;
		$reportImg['photo'] = ['path' => $photoPath,'width'=>800,'height'=>600];
		$reportImg['maping'] = ['path' => $mapingPath,'width'=>800,'height'=>600];
		$wordData['data'] = $report;
		$wordData['reportImg'] = $reportImg;
		return $wordData;
	}

	//检查记录表
	public function createRecord (Company $company,$checkinfo,$checkdetail, $checkUser, $address, $safeUser, $checkAccords) {
		foreach ( $checkdetail as $k => $v ) {
			$checkdetail[$k]->picturesArr = [];
			if ( !empty( $v->pictures ) ) {
				$checkdetail[$k]->picturesArr = explode( ',', trim( $v->pictures, ',' ) );
			}
		}
		/*区分消防非消防*/
		$fireArr = [];
		$unfireArr = [];
		foreach ( $checkdetail as $k => $v ) {
			if ( $v->type == 1 ) {
				$fireArr[] = $v;
			} else if ( $v->type == 2 ) {
				$unfireArr[] = $v;
			}
		}
		$exportLogData = [];
		$exportFireLogData = [];
		$exportUnFireLogData = [];
		$exportLogData['company'] = $company->comName;
		if(!empty($safeUser)) {
			$exportLogData['safeUser'] = $safeUser->name;
			$exportLogData['safePhone'] = $safeUser->phone;
		} else {
			$exportLogData['safeUser'] = '';
			$exportLogData['safePhone'] = '';
		}
		$exportLogData['address'] = $address['city'] . $address['district'] . $address['street'] . $company->address;
		$exportLogData['checkUser'] = $checkUser->name;
		$exportLogData['checkTime'] = date('Y',strtotime($checkinfo['created'])).'年'.date('m',strtotime($checkinfo['created'])).'月'.date('d',strtotime($checkinfo['created'])).'日';
		/*检查记录表*/
		$fireArchivesNum = 0;
		$fireWorkNum = 0;
		$productArchivesNum = 0;
		$productWorkNum = 0;
		foreach ( $fireArr as $key => $value ) {
			$tmpArr = [];
			$tmpCheck = $value;
			$tmpChekPictureArr = $tmpCheck->picturesArr;
			$tmpArr['num'] = $key + 1;
			if($tmpCheck->status==1) {
				$tmpArr['category'] = '管<w:br />理<w:br />档<w:br />案<w:br />类';
				$fireArchivesNum += 1;
			} else {
				$tmpArr['category'] = '作<w:br />业<w:br />现<w:br />场<w:br />类';
				$fireWorkNum += 1;
			}
			if(!empty($value->entryId)) {
				$tmpContent = $tmpCheck->content;
				$tmpContent = str_replace(";", ",", trim($tmpContent,";"));
				$tmpArr['dagerDescription'] =  $tmpContent ? trim($tmpCheck->necontent . ',' . $tmpContent, ',').'。':$tmpCheck->necontent.'。';
			} else {
				$tmpArr['dagerDescription'] =  $tmpCheck->contentexist.'。';
			}
			
			$tmpArr['reformProposal'] = $tmpCheck->entry;
			if ( !empty( $tmpChekPictureArr )  &&  file_exists('.' . $tmpChekPictureArr[0])) {
				$tmpArr['dagerPicture'] = array('path'=>'.' . $tmpChekPictureArr[0], 'width'=>237, 'height'=>151);
			} else {
				$tmpArr['dagerPicture'] = '';
			}

			$tmpArr['accords'] = "";
			foreach($checkAccords as $k=>$v) {
				if($value->entryId==$v->entryId) {
					$tmpArr['accords'] = $tmpArr['accords']?$tmpArr['accords']."<w:br />".$v->title.'<w:br />'.preg_replace("/(<br\/>)/i",
                    "<w:br />",
                    $v->content):$v->title.'<w:br />'.preg_replace("/(<br\/>)/i",
                    "<w:br />",
                    $v->content);
					
				}
			}
			$tmpArr['remark'] = '';
			$exportFireLogData[$key + 1] = $tmpArr;
		}
		foreach ( $unfireArr as $key => $value ) {
			$tmpArr = [];
			$tmpCheck = $value;
			$tmpArr['num'] = $key + 1;
			if($tmpCheck->status==1) {
				$tmpArr['category'] = '管<w:br />理<w:br />档<w:br />案<w:br />类';
				$productArchivesNum += 1;
			} else {
				$tmpArr['category'] = '作<w:br />业<w:br />现<w:br />场<w:br />类';
				$productWorkNum += 1;
			}
			if(!empty($value->entryId)) {
				$tmpContent = $tmpCheck->content;
				$tmpContent = str_replace(";", ",", trim($tmpContent,";"));
				$tmpArr['dagerDescription'] = $tmpContent ? trim($tmpCheck->necontent . ',' . $tmpContent, ',').'。':$tmpCheck->necontent.'。';
			} else {
				$tmpArr['dagerDescription'] = $tmpCheck->contentexist.'。';
			}
			$tmpArr['reformProposal'] = $tmpCheck->entry;
			if ( !empty( $tmpCheck->picturesArr )   &&  file_exists('.' . $tmpCheck->picturesArr[0])) {
				$tmpArr['dagerPicture'] = array('path'=>'.' . $tmpCheck->picturesArr[0], 'width'=>237, 'height'=>151);
			} else {
				$tmpArr['dagerPicture'] = '';
			}
			$tmpArr['accords'] = "";
			foreach($checkAccords as $k=>$v) {
				if($value->entryId==$v->entryId) {
					$tmpArr['accords'] = $tmpArr['accords']?$tmpArr['accords']."<w:br />".$v->title.'<w:br />'.preg_replace("/(<br\/>)/i",
                    "<w:br />",
                    $v->content):$v->title.'<w:br />'.preg_replace("/(<br\/>)/i",
                    "<w:br />",
                    $v->content);
					
				}
			}
			$tmpArr['remark'] = '';
			$exportUnFireLogData[$key + 1] = $tmpArr;
		}
		$data['exportLogData'] = $exportLogData;
		$data['exportFireLogData'] = $exportFireLogData;
		$data['exportFireNum']['dangerNum'] = count($exportFireLogData);
		$data['exportFireNum']['archivesNum'] = $fireArchivesNum;
		$data['exportFireNum']['workNum'] = $fireWorkNum;
		$data['exportUnFireLogData'] = $exportUnFireLogData;
		$data['exportUnfireNum']['dangerNum'] = count($exportUnFireLogData);
		$data['exportUnfireNum']['archivesNum'] = $productArchivesNum;
		$data['exportUnfireNum']['workNum'] = $productWorkNum;
		return $data;

	}

	//风险点名册
	public function createRisk ( Company $company, Comcheck $checkinfo,$checkdetail, $comcheckGroup, $address ) {
		$year = date('Y',strtotime($checkinfo->created));
		$month = date('m',strtotime($checkinfo->created));
		$day = date('d',strtotime($checkinfo->created));
		$riskPointArr = [];
		$riskPointArr['companyName'] = $company->comName;
		$riskPointArr['street'] = $address['street'];
		$riskPointArr['year'] = $year;
		$riskPointArr['month'] = $month;
		$riskPointArr['day'] = $day;
		$riskPointArr['comSignature'] = '.' . $checkinfo->comsignature;
		$riskPointArr['leader'] = $company->leader;
		$riskPointArr['leaderPhone'] = $company->leaderPhone;
		$riskPointArr['address'] = $address['city'] . $address['district'] . $address['street'] . $company->address;
		$riskPointArr['postcode'] = $company->postcode;
		$riskPointArr['product'] = $company->product;
		$riskPointArr['material'] = $company->material;
		$riskPointArr['assets'] = $company->assets;
		$riskPointArr['income'] = $company->income;
		$riskPointArr['space'] = $company->space;
		$riskPointArr['workersNum'] = $company->workersNum;
		$riskPoints = [];

		foreach ( $comcheckGroup as $k => $v ) {

			$tmpArr = [];
			$tmpArr['number'] = $k + 1;
			$tmpArr['year'] = $year;
			$tmpArr['month'] = $month;
			$tmpArr['day'] = $day;
			$tmpArr['riskName'] = $v->name;
			$tmpArr['riskLocation'] = $v->riskPoint;
			$tmpArr['accidentType'] = $v->accidentType;
			$tmpArr['lossPrediction'] = $v->lossPrediction;
			if ( !empty( $v->riskLevel ) ) {
				$tmpArr['riskLevel'] = $v->riskLevel;
			} else {
				$tmpArr['riskLevel'] = '';
			}
			$tmpArr['companyName'] = $company->comName;
			$tmpArr['leader'] = $company->leader;
			$tmpArr['leaderPhone'] = $company->leaderPhone;
			$tmpArr['measures'] = $v->measures;
			$tmpArr['emergencyMeasure'] = $v->emergencyMeasure;
			$tmpArr['street'] = $address['street'];
			$tmpArr['hiddenDangerSituation'] = '';
			foreach ($checkdetail as $kk => $vv) {
				if($v->groupId == $vv->groupId) {
					$tmpArr['hiddenDangerSituation'] .= $vv->necontent.$vv->content;
				}
			}
			$riskPoints[] = $tmpArr;
		}
		$wordData['riskPointArr'] = $riskPointArr;
		$wordData['riskPoints'] = $riskPoints;
		return $wordData;
	}

	//基础档案
	public function createArchives($company, $safeuser, $manager,$address,$check,$checkdetail,$checkUser,$checkAccords)
	{
		$year = date('Y', strtotime($check['created']));
		$month = date('m', strtotime($check['created']));
		$day = date('d', strtotime($check['created']));
		$hour = date('H', strtotime($check['created']));
		$fireArr = array();
		$unfireArr = array();
		foreach ($checkdetail as $k => $v)
		{
			if($v->type == 1) {
				$fireArr[] = $v;
			}
			if($v->type == 2) {
				$unfireArr[] = $v;
			}
		}
		$wordData = array();
		$imgData = array();
		$wordLogData = array();
		$wordData['company'] = $company->comName;
		$wordData['address'] = $address['province'].$address['city'].$address['district'].$address['street'].$company->address;
		$wordData['space'] = $company->space;
		$wordData['floorSpace'] = $company->area;
		$wordData['workNum'] = $company->workersNum;
		$wordData['leader'] = $company->leader;
		if(!empty($company->leaderPhone)) {
			$wordData['leaderPhone'] = $company->leaderPhone;
		} else {
			$wordData['leaderPhone'] = "&#8194;&#8194;&#8194;&#8194;&#8194;&#8194;&#8194;&#8194;&#8194;&#8194;&#8194;";
		}
		if(!empty($manager)) {
			$wordData['manager'] = $manager->name;
			$wordData['managerPhone'] = $manager->phone;
		} else {
			$wordData['manager'] = "&#8194;&#8194;&#8194;";
			$wordData['managerPhone'] = "&#8194;&#8194;&#8194;&#8194;&#8194;&#8194;&#8194;&#8194;&#8194;&#8194;&#8194;";
		}
		$wordData['checkTime'] = $year.'年'.$month.'月'.$day.'日';
		$wordData['accompany'] = $company->accompany;
		$wordData['checkUser'] = $checkUser->name;
		if(!empty($company->service)) {
			$wordData['serviceUser'] = $company->service;
		} else {
			$wordData['serviceUser'] = "&#8194;&#8194;&#8194;&#8194;&#8194;&#8194;";
		}
		$wordData['checkPhone'] = $checkUser->phone;

		/*统计数量*/
		$seriousDangerNum = 0;
		$dangerNum = 0;
		$fireArchivesNum = 0;/*消防基础档案*/
		$fireWorkNum = 0;/*消防作业现场类*/
		$productArchivesNum = 0;/*生产基础档案*/
		$productWorkNum = 0;/*生产作业现场*/
		foreach ($fireArr as $key => $value) {
			if($value->isfire==1) {
				$seriousDangerNum += 1;
			} else {
				$dangerNum += 1;
			}
			if($value->status==1) {
				$fireArchivesNum += 1;
			} else {
				$fireWorkNum += 1;
			}
		}
		foreach ($unfireArr as $key => $value) {
			if($value->isfire==1) {
				$seriousDangerNum += 1;
			} else {
				$dangerNum += 1;
			}
			if($value->status==1) {
				$productArchivesNum += 1;
			} else {
				$productWorkNum += 1;
			}
		}

		$wordData['seriousDangerNum'] = $seriousDangerNum;
		$wordData['dangerNum'] = $dangerNum;
		$wordData['fireArchivesNum'] = $fireArchivesNum;
		$wordData['fireWorkNum'] = $fireWorkNum;
		$wordData['productArchivesNum'] = $productArchivesNum;
		$wordData['productWorkNum'] = $productWorkNum;
		$wordData['fireNum'] = $fireArchivesNum+$fireWorkNum;
		$wordData['productNum'] = $productArchivesNum + $productWorkNum;
		$wordData['archivesNum'] = $fireArchivesNum + $productArchivesNum;
		$wordData['workTotalNum'] = $fireWorkNum+$productWorkNum;
		$wordData['total'] = $fireArchivesNum + $productArchivesNum+$fireWorkNum+$productWorkNum;
		$wordData['year'] = $year;
		$wordData['month'] = $month;
		$wordData['day'] = $day;
		$wordData['startHour'] = $hour;
		$wordData['endHour'] = date('H', strtotime('+1 hour',strtotime($check['created'])));

		if(!empty($company->license) && file_exists('.'. $company->license)) {
			$imgData['license'] = array('path'=>'.'.$company->license,'width'=>614,'height'=>794);
		} else {
			$imgData['license'] = '';
		}

		if(!empty($company->photo) && file_exists('.'. $company->photo)) {
			$imgData['photo'] = ['path' => '.'.$company->photo,'width'=>567,'height'=>427];
		} else {
			$imgData['photo'] = '';
		}

		if(!empty($check->mapimg) && file_exists('.'. $check->mapimg)) {
			$imgData['map'] = ['path' => '.'.$check->mapimg,'width'=>567,'height'=>427];
		} else {
			$imgData['map'] = '';
		}
		/*隐患告知单*/
		$i = 0;
		$j = 0;
		$fireArchives = "";
		$fireWork = "";
		$productArchives = "";
		$productWork = "";
		foreach ( $fireArr as $k => $v ) {
			if($v->status==1) {
				$i++;
				if(!empty($v->entryId)) {
					$tmpContent = $v->content;
					$tmpContent = str_replace(";", ",", trim($tmpContent,";"));
					$fireArchives .= '（' . $i . '）' . trim($v->necontent . ',' .$tmpContent, ',') . '；<w:br />';
				} else {
					$fireArchives .= '（' . $i . '）' . $v->contentexist . '；<w:br />';
				}
				
			}
		}
		foreach ( $fireArr as $k => $v ) {
			if($v->status==2) {
				$i++;
				if(!empty($v->entryId)) {
					$tmpContent = $v->content;
					$tmpContent = str_replace(";", ",", trim($tmpContent,";"));
					$fireWork .= '（' . $i . '）' . trim($v->necontent . ',' . $tmpContent, ',') . '；<w:br />';
				} else {
					$fireWork .= '（' . $i . '）' . $v->contentexist . '；<w:br />';
				}
				
			}
		}

		$fireArchives = mb_substr($fireArchives,0,-8,'utf-8');
		$fireWork = mb_substr($fireWork,0,-8,'utf-8');	
		if(!empty($fireArchives)&&!empty($fireWork)) {
			$fireWork = mb_substr($fireWork,0,-1,'utf-8')."。";	
		} else if(!empty($fireArchives)) {
			$fireArchives = mb_substr($fireArchives,0,-1,'utf-8')."。";
			$fireWork = '无';
		} else if(!empty($fireWork)) {
			$fireWork = mb_substr($fireWork,0,-1,'utf-8')."。";
			$fireArchives = '无';
		}

		foreach ( $unfireArr as $k => $v ) {
			if($v->status==1) {
				$j++;
				if(!empty($v->entryId)) {
					$tmpContent = $v->content;
					$tmpContent = str_replace(";", ",", trim($tmpContent,";"));
					$productArchives .= '（' . $j . '）' . trim($v->necontent . ',' . $tmpContent, ',') . '；<w:br />';
				} else {
					$productArchives .= '（' . $j . '）' . $v->contentexist . '；<w:br />';
				}
				
			}
		}
		foreach ( $unfireArr as $k => $v ) {
			if($v->status==2) {
				$j++;
				if(!empty($v->entryId)) {
					$tmpContent = $v->content;
					$tmpContent = str_replace(";", ",", trim($tmpContent,";"));
					$productWork .= '（' . $j . '）' . trim($v->necontent . ',' . $tmpContent, ',') . '；<w:br />';
				} else {
					$productWork .= '（' . $j . '）' . $v->contentexist . '；<w:br />';
				}
				
			}
		}
		$productArchives = mb_substr($productArchives,0,-8,'utf-8');
		$productWork = mb_substr($productWork,0,-8,'utf-8');
		if(!empty($productArchives)&&!empty($productWork)) {
			$productWork = mb_substr($productWork,0,-1,'utf-8')."。";
		} else if(!empty($productArchives)) {
			$productArchives = mb_substr($productArchives,0,-1,'utf-8')."。";
			$productWork = '无';
		} else if(!empty($productWork)) {
			$productWork = mb_substr($productWork,0,-1,'utf-8')."。";
			$productArchives = '无';
		}
		$wordData['fireArchivesContent'] = $fireArchives;
		$wordData['fireWorkContent'] = $fireWork;
		$wordData['productArchivesContent'] = $productArchives;
		$wordData['productWorkContent'] = $productWork;

		/*公司和检查人员签名*/
        if( $check->comsignature && file_exists('.'. $check->comsignature)){
            $imgData['companySignature'] = ['path' => '.'. $check->comsignature,'width'=>120,'height'=>90];
        }else{
            $imgData['companySignature'] = '';
        }
        if( $check->usersignature && file_exists('.'. $check->usersignature)){
            $imgData['userSignature'] = ['path' => '.'. $check->usersignature,'width'=>120,'height'=>90];
        }else{
            $imgData['userSignature'] = '';
        }


		/*检查记录*/
		foreach ( $fireArr as $key => $value ) {
			$tmpArr = [];
			$tmpCheck = $value;
			$tmpChekPictureArr = $tmpCheck->picturesArr;
			$tmpArr['fireNumber'] = $key + 1;
			if($tmpCheck->status==1) {
				$tmpArr['fireCategory'] = '管<w:br />理<w:br />档<w:br />案<w:br />类';
			} else {
				$tmpArr['fireCategory'] = '作<w:br />业<w:br />现<w:br />场<w:br />类';
			}
			if(!empty($tmpCheck->entryId)) {
				$tmpContent = $tmpCheck->content;
				$tmpContent = str_replace(";", ",", trim($tmpContent,";"));
				$tmpArr['fireDangerDescription'] =  $tmpCheck->content ? trim($tmpCheck->necontent . ',' . $tmpContent, ',').'。':$tmpCheck->necontent.'。';
			} else {
				$tmpArr['fireDangerDescription'] =  $tmpCheck->contentexist.'。';
			}
			$tmpArr['fireReformProposal'] = $tmpCheck->entry;
			if ( !empty( $tmpChekPictureArr )  && file_exists('.'.$tmpChekPictureArr[0]) ) {
				$tmpArr['fireDangerPicture'] = array('path'=>'.' . $tmpChekPictureArr[0], 'width'=>237, 'height'=>151);
			} else {
				$tmpArr['fireDangerPicture'] = '';
			}
			$tmpArr['fireAccords'] = "";
			foreach($checkAccords as $k=>$v) {
				if($value->entryId==$v->entryId) {
					$tmpArr['fireAccords'] = $tmpArr['fireAccords']?$tmpArr['fireAccords']."<w:br />".$v->title.'<w:br />'.preg_replace("/(<br\/>)/i",
                    "<w:br />",
                    $v->content):$v->title.'<w:br />'.preg_replace("/(<br\/>)/i",
                    "<w:br />",
                    $v->content);
				}
			}
			$tmpArr['fireRemark'] = '';
			$wordLogData['fire'][$key+1] = $tmpArr;
		}
		foreach ( $unfireArr as $key => $value ) {
			$tmpArr = [];
			$tmpCheck = $value;
			$tmpArr['productNumber'] = $key + 1;
			if($tmpCheck->status==1) {
				$tmpArr['productCategory'] = '管<w:br />理<w:br />档<w:br />案<w:br />类';
			} else {
				$tmpArr['productCategory'] = '作<w:br />业<w:br />现<w:br />场<w:br />类';
			}
			if(!empty($tmpCheck->entryId)) {
				$tmpContent = $tmpCheck->content;
				$tmpContent = str_replace(";", ",", trim($tmpContent,";"));
				$tmpArr['productDangerDescription'] = $tmpCheck->content ? trim($tmpCheck->necontent . ',' . $tmpContent, ',').'。':$tmpCheck->necontent.'。';
			} else {
				$tmpArr['productDangerDescription'] = $tmpCheck->contentexist.'。';
			}
			
			$tmpArr['productReformProposal'] = $tmpCheck->entry;
			if ( !empty( $tmpCheck->picturesArr )  && file_exists('.'.$tmpCheck->picturesArr[0])) {
				$tmpArr['productDangerPicture'] = array('path'=>'.' . $tmpCheck->picturesArr[0], 'width'=>237, 'height'=>151);
			} else {
				$tmpArr['productDangerPicture'] = '';
			}
			$tmpArr['productAccords'] = "";
			foreach($checkAccords as $k=>$v) {
				if($value->entryId==$v->entryId) {
					$tmpArr['productAccords'] = $tmpArr['productAccords']?$tmpArr['productAccords']."<w:br />".$v->title.'<w:br />'.preg_replace("/(<br\/>)/i",
                    "<w:br />",
                    $v->content):$v->title.'<w:br />'.preg_replace("/(<br\/>)/i",
                    "<w:br />",
                    $v->content);
				}
			}
			$tmpArr['productRemark'] = '';
			$wordLogData['product'][$key + 1] = $tmpArr;
		}

		$returnData = array();
		$returnData['basicData'] = $wordData;
		$returnData['imgData'] = $imgData;
		$returnData['record'] = $wordLogData;

		return $returnData;
		
		
	}

	//生成统计图片
	public function generateImg($checkdetail) 
	{
        $fireArchivesNum = 0;
        $fireWorkNum = 0;
        $unfireArchivesNum = 0;
        $unfireWorkNum = 0;
        foreach($checkdetail as $k=>$v) {
        	if($v->type==1) {/*消防*/
        		if($v->status==1) {/*管理档案类*/
        			$fireArchivesNum += 1;	
        		} else {
        			$fireWorkNum += 1;
        		}
        	} else if($v->type==2){
        		if($v->status==1) {
        			$unfireArchivesNum += 1;
        		} else {
        			$unfireWorkNum += 1;
        		}
        	}
        }

        /*选出最大值*/
        $max = max($fireArchivesNum,$fireWorkNum,$unfireArchivesNum,$unfireWorkNum);
        $len = 10;
        if($max > 10) {
            $len = $max;
        } else {
            $len = 10;
        }

        require_once ('jpgraph/src/jpgraph.php');
        
        require_once ('jpgraph/src/jpgraph_bar.php');

        $data = array(1 => array(0=>$fireArchivesNum,1=>$unfireArchivesNum),2 => array(0=>$fireWorkNum,1=>$unfireWorkNum));
        $graph = new \Graph(567,227);


        $graph->SetScale("textlin");
        $graph->SetScale("textlin",0,$len);
        $graph->SetTheme(new \VividTheme());

        $graph->yscale->ticks->Set(10,2);

        $graph->yaxis->scale->SetGrace(20);

        $graph->xaxis->SetTickLabels(array(iconv_arr('管理档案类'),iconv_arr('作业现场类')));//

        $plot = array();
        $plot[1] = new \BarPlot($data[1]);
        $legend1 = iconv_arr('消防安全隐患');
        $plot[1]->SetLegend($legend1);

        
        $plot[2] = new \BarPlot($data[2]);
        $legend2 = iconv_arr('生产安全隐患');
        $plot[2]->SetLegend($legend2);
        
        $gbplot = new \GroupBarPlot(array($plot[1], $plot[2]));

        $graph->Add($gbplot);
        $plot[1]->value->show();
        $plot[1]->value->SetFormat('%d');
        $plot[2]->value->show();//设置显示数字
        $plot[2]->value->SetFormat('%d');//在柱形图中显示格式化数量

        $a=iconv_arr(array("管理档案类","作业现场类"));
        $graph->xaxis->SetTickLabels($a);//设置X轴
        $graph->legend->SetAbsPos(0.5,0.98,'right','top');//设置图例位置
        $graph->xaxis->SetFont(FF_SIMSUN);//设置X轴的字体
        $graph->legend->SetFont(FF_SIMSUN);//设置图例字体

        $imgname=rand(1000,10000).time().'.jpg';
        $fileDirectory = 'storage/word_static_images/'.date('Ymd');
        File::isDirectory($fileDirectory) or File::makeDirectory($fileDirectory);
        $img = $fileDirectory.'/'.$imgname;
        // Display the graph
        $returnData = array();
        try{
        	$graph->Stroke($img);
        	$returnData['dangerBar'] = array('path'=>'./'.$img,'width'=>567,'height'=>227);
        } catch(Exception $e){
        	$returnData['dangerBar'] = array();
        }

        return $returnData;

	}

	public function generateCheckAgainBar($checkagaindetail,$checkdetail)
	{
		require_once ('jpgraph/src/jpgraph.php');

		require_once ('jpgraph/src/jpgraph_bar.php');

        require_once ('jpgraph/src/jpgraph_pie.php');

        require_once ('jpgraph/src/jpgraph_pie3d.php');

        /*柱状图*/
		$fireArchivesNum = 0;
        $fireWorkNum = 0;
        $unfireArchivesNum = 0;
        $unfireWorkNum = 0;
        foreach($checkdetail as $k=>$v) {
        	if($v->type==1) {/*消防*/
        		if($v->group_status==1) {/*管理档案类*/
        			$fireArchivesNum += 1;	
        		} else {
        			$fireWorkNum += 1;
        		}
        	} else if($v->type==2) {
        		if($v->group_status==1) {
        			$unfireArchivesNum += 1;
        		} else {
        			$unfireWorkNum += 1;
        		}
        	}
        }

        /*选出最大值*/
        $max = max($fireArchivesNum,$fireWorkNum,$unfireArchivesNum,$unfireWorkNum);
        $len = 10;
        if($max > 10) {
            $len = $max;
        } else {
            $len = 10;
        }

        $data = array(1 => array(0=>$fireArchivesNum,1=>$unfireArchivesNum),2 => array(0=>$fireWorkNum,1=>$unfireWorkNum));
        $graph = new \Graph(567,227);

        $graph->SetScale("textlin");
        $graph->SetScale("textlin",0,$len);
        $graph->SetTheme(new \VividTheme());

        $graph->yscale->ticks->Set(10,2);

        $graph->yaxis->scale->SetGrace(20);

        $graph->xaxis->SetTickLabels(array(iconv_arr('管理档案类'),iconv_arr('作业现场类')));//

        $plot = array();
        $plot[1] = new \BarPlot($data[1]);
        $legend1 = iconv_arr('消防安全隐患');
        $plot[1]->SetLegend($legend1);

        
        $plot[2] = new \BarPlot($data[2]);
        $legend2 = iconv_arr('生产安全隐患');
        $plot[2]->SetLegend($legend2);
        
        $gbplot = new \GroupBarPlot(array($plot[1], $plot[2]));

        $graph->Add($gbplot);
        $plot[1]->value->show();
        $plot[1]->value->SetFormat('%d');
        $plot[2]->value->show();//设置显示数字
        $plot[2]->value->SetFormat('%d');//在柱形图中显示格式化数量

        $a=iconv_arr(array("管理档案类","作业现场类"));
        $graph->xaxis->SetTickLabels($a);//设置X轴
        $graph->legend->SetAbsPos(0.5,0.98,'right','top');//设置图例位置
        $graph->xaxis->SetFont(FF_SIMSUN);//设置X轴的字体
        $graph->legend->SetFont(FF_SIMSUN);//设置图例字体

        $imgname=rand(1000,10000).time().'.jpg';
        $fileDirectory = 'storage/word_static_images/'.date('Ymd');
        File::isDirectory($fileDirectory) or File::makeDirectory($fileDirectory);
        $img = $fileDirectory.'/'.$imgname;
        // Display the graph
        $returnData = array();
        try{
        	$graph->Stroke($img);
        	$returnData['dangerBar'] = array('path'=>'./'.$img,'width'=>567,'height'=>227);
        } catch(Exception $e){
        	$returnData['dangerBar'] = array();
        }

        /*饼图*/
        /*处理数据*/
        $fireData = array();
        $productData = array();
        $allData = array();
        $fireNoRedirectNum = 0;
        $firePartRedirectNum = 0;
        $fireAllRedirectNum = 0;
        $productNoRedirectNum = 0;
        $productPartRedirectNum = 0;
        $productAllRedirectNum = 0;
        $totalNoRedirectNum = 0;
        $totalPartRedirectNum = 0;
        $totalAllRedirectNum = 0;
        foreach($checkagaindetail as $k=>$v) {
        	if($v->type==1) {/*消防*/
        		if($v->status==1) {
	                $fireNoRedirectNum += 1;
	            } else if($v->status==2) {
	                $firePartRedirectNum += 1;
	            } else if($v->status==3) {
	                $fireAllRedirectNum += 1;
	            }
        	} else if($v->type==2) {/*非消防*/
        		if($v->status==1) {
	                $productNoRedirectNum += 1;
	            } else if($v->status==2) {
	                $productPartRedirectNum += 1;
	            } else if($v->status==3) {
	                $productAllRedirectNum += 1;
	            }
        	}
        }
        $totalNoRedirectNum = $fireNoRedirectNum + $productNoRedirectNum;
        $totalPartRedirectNum = $firePartRedirectNum + $productPartRedirectNum;
        $totalAllRedirectNum = $fireAllRedirectNum + $productAllRedirectNum;

        $fireData = array($fireAllRedirectNum,$firePartRedirectNum,$fireNoRedirectNum);
        $productData = array($productAllRedirectNum,$productPartRedirectNum,$productNoRedirectNum);
        $allData = array($totalAllRedirectNum,$totalPartRedirectNum,$totalNoRedirectNum);
        
        /*消防整改饼图*/
        $legend = array('已经整改','部分整改','未整改');
	    $legend = iconv_arr($legend);
        $fireDataMax = max($fireData);
        if($fireDataMax==0) {
        	$returnData['fireRedirectPie'] = array('path'=>'./storage/word_static_images/small_zero.png','width'=>272,'height'=>152);
        } else {
        	$graph_pie_fire = new \PieGraph(280,160); 
	        $graph_pie_fire->SetShadow();  
	        $theme_class= new \AquaTheme();
			$graph_pie_fire->SetTheme($theme_class);
	        
	        $pieplot = new \PiePlot3D($fireData);  //创建PiePlot3D对象  
	        $pieplot->SetSize(0.28);//设置饼图大小
	        $pieplot->SetCenter(0.5, 0.5); //设置饼图中心的位置  
	        $pieplot->SetLegends(iconv_arr($legend)); //设置图例  
	        $graph_pie_fire->legend->SetFont(FF_SIMSUN,FS_BOLD);  

	          
	        $graph_pie_fire->Add($pieplot);

	        $pie_fire_imgname=rand(1000,10000).time().'_firepie.jpg';
	        $fileDirectory = 'storage/word_static_images/'.date('Ymd');
	        File::isDirectory($fileDirectory) or File::makeDirectory($fileDirectory);
	        $pie_fire_img = $fileDirectory.'/'.$pie_fire_imgname;
	        // Display the graph
	        try{
	        	$graph_pie_fire->Stroke($pie_fire_img);
	        	$returnData['fireRedirectPie'] = array('path'=>'./'.$pie_fire_img,'width'=>272,'height'=>152);
	        } catch(Exception $e){
	        	$returnData['fireRedirectPie'] = array();
	        } 
        }
        

        /*生产整改饼图*/
        $productDataMax = max($productData);
        if($productDataMax==0) {
        	$returnData['productRedirectPie'] = array('path'=>'./storage/word_static_images/small_zero.png','width'=>272,'height'=>152);
        } else {
        	$graph_pie_product = new \PieGraph(280,160);  
	        $graph_pie_product->SetShadow();  
	        $theme_class= new \AquaTheme();
			$graph_pie_product->SetTheme($theme_class);
	       
	        $pieplot_product = new \PiePlot3D($productData);  //创建PiePlot3D对象  
	        $pieplot_product->SetSize(0.28);//设置饼图大小
	        $pieplot_product->SetCenter(0.5, 0.5); //设置饼图中心的位置  
	        $pieplot_product->SetLegends(iconv_arr($legend)); //设置图例  
	        $graph_pie_product->legend->SetFont(FF_SIMSUN,FS_BOLD);  
	          
	        $graph_pie_product->Add($pieplot_product);  

	        $pie_product_imgname=rand(1000,10000).time().'_fireproduct.jpg';
	        $fileDirectory = 'storage/word_static_images/'.date('Ymd');
	        File::isDirectory($fileDirectory) or File::makeDirectory($fileDirectory);
	        $pie_product_img = $fileDirectory.'/'.$pie_product_imgname;
	        // Display the graph
	        try{
	        	$graph_pie_product->Stroke($pie_product_img);
	        	$returnData['productRedirectPie'] = array('path'=>'./'.$pie_product_img,'width'=>272,'height'=>152);
	        } catch(Exception $e){
	        	$returnData['productRedirectPie'] = array();
	        } 
        }
        
        /*所有整改饼图*/
        $allDataMax = max($allData);
        if($allDataMax==0) {
        	$returnData['allRedirectPie'] = array('path'=>'./storage/word_static_images/all_zero.png','width'=>467,'height'=>227);
        } else {
        	$graph_pie_all = new \PieGraph(480,240);  
	        $graph_pie_all->SetShadow();
	        $theme_class= new \AquaTheme();
			$graph_pie_all->SetTheme($theme_class);  
	       
	        $pieplot_all = new \PiePlot3D($allData);  //创建PiePlot3D对象 
	        $pieplot_all->SetSize(0.34);//设置饼图大小 
	        $pieplot_all->SetCenter(0.5, 0.5); //设置饼图中心的位置  
	        $pieplot_all->SetLegends(iconv_arr($legend)); //设置图例  
	        $graph_pie_all->legend->SetFont(FF_SIMSUN,FS_BOLD);  
	          
	        $graph_pie_all->Add($pieplot_all); 

	        $pie_all_imgname=rand(1000,10000).time().'_fireall.jpg';
	        $fileDirectory = 'storage/word_static_images/'.date('Ymd');
	        File::isDirectory($fileDirectory) or File::makeDirectory($fileDirectory);
	        $pie_all_img = $fileDirectory.'/'.$pie_all_imgname;
	        // Display the graph
	        try{
	        	$graph_pie_all->Stroke($pie_all_img);
	        	$returnData['allRedirectPie'] = array('path'=>'./'.$pie_all_img,'width'=>467,'height'=>227);
	        } catch(Exception $e){
	        	$returnData['allRedirectPie'] = array();
	        } 
        }

        return $returnData;
	}


	public function generateApiCheckAgainBar($checkagaindetail,$checkdetail)
	{
		require_once ('jpgraph/src/jpgraph.php');

		require_once ('jpgraph/src/jpgraph_bar.php');

        require_once ('jpgraph/src/jpgraph_pie.php');

        require_once ('jpgraph/src/jpgraph_pie3d.php');

        /*柱状图*/
		$fireArchivesNum = 0;
        $fireWorkNum = 0;
        $unfireArchivesNum = 0;
        $unfireWorkNum = 0;
        foreach($checkdetail as $k=>$v) {
        	if($v['type']==1) {/*消防*/
        		if($v['group_status']==1) {/*管理档案类*/
        			$fireArchivesNum += 1;	
        		} else {
        			$fireWorkNum += 1;
        		}
        	} else if($v['type']==2) {
        		if($v['group_status']==1) {
        			$unfireArchivesNum += 1;
        		} else {
        			$unfireWorkNum += 1;
        		}
        	}
        }

        /*选出最大值*/
        $max = max($fireArchivesNum,$fireWorkNum,$unfireArchivesNum,$unfireWorkNum);
        $len = 10;
        if($max > 10) {
            $len = $max;
        } else {
            $len = 10;
        }

        $data = array(1 => array(0=>$fireArchivesNum,1=>$unfireArchivesNum),2 => array(0=>$fireWorkNum,1=>$unfireWorkNum));
        $graph = new \Graph(567,227);

        $graph->SetScale("textlin");
        $graph->SetScale("textlin",0,$len);
        $graph->SetTheme(new \VividTheme());

        $graph->yscale->ticks->Set(10,2);

        $graph->yaxis->scale->SetGrace(20);

        $graph->xaxis->SetTickLabels(array(iconv_arr('管理档案类'),iconv_arr('作业现场类')));//

        $plot = array();
        $plot[1] = new \BarPlot($data[1]);
        $legend1 = iconv_arr('消防安全隐患');
        $plot[1]->SetLegend($legend1);

        
        $plot[2] = new \BarPlot($data[2]);
        $legend2 = iconv_arr('生产安全隐患');
        $plot[2]->SetLegend($legend2);
        
        $gbplot = new \GroupBarPlot(array($plot[1], $plot[2]));

        $graph->Add($gbplot);
        $plot[1]->value->show();
        $plot[1]->value->SetFormat('%d');
        $plot[2]->value->show();//设置显示数字
        $plot[2]->value->SetFormat('%d');//在柱形图中显示格式化数量

        $a=iconv_arr(array("管理档案类","作业现场类"));
        $graph->xaxis->SetTickLabels($a);//设置X轴
        $graph->legend->SetAbsPos(0.5,0.98,'right','top');//设置图例位置
        $graph->xaxis->SetFont(FF_SIMSUN);//设置X轴的字体
        $graph->legend->SetFont(FF_SIMSUN);//设置图例字体

        $imgname=rand(1000,10000).time().'.jpg';
        $fileDirectory = 'storage/word_static_images/'.date('Ymd');
        File::isDirectory($fileDirectory) or File::makeDirectory($fileDirectory);
        $img = $fileDirectory.'/'.$imgname;
        // Display the graph
        $returnData = array();
        try{
        	$graph->Stroke($img);
        	$returnData['dangerBar'] = array('path'=>'./'.$img,'width'=>567,'height'=>227);
        } catch(Exception $e){
        	$returnData['dangerBar'] = array();
        }

        /*饼图*/
        /*处理数据*/
        $fireData = array();
        $productData = array();
        $allData = array();
        $fireNoRedirectNum = 0;
        $firePartRedirectNum = 0;
        $fireAllRedirectNum = 0;
        $productNoRedirectNum = 0;
        $productPartRedirectNum = 0;
        $productAllRedirectNum = 0;
        $totalNoRedirectNum = 0;
        $totalPartRedirectNum = 0;
        $totalAllRedirectNum = 0;
        foreach($checkagaindetail as $k=>$v) {
        	if($v['type']==1) {/*消防*/
        		if($v['status']==1) {
	                $fireNoRedirectNum += 1;
	            } else if($v['status']==2) {
	                $firePartRedirectNum += 1;
	            } else if($v['status']==3) {
	                $fireAllRedirectNum += 1;
	            }
        	} else if($v['type']==2) {/*非消防*/
        		if($v['status']==1) {
	                $productNoRedirectNum += 1;
	            } else if($v['status']==2) {
	                $productPartRedirectNum += 1;
	            } else if($v['status']==3) {
	                $productAllRedirectNum += 1;
	            }
        	}
        }
        $totalNoRedirectNum = $fireNoRedirectNum + $productNoRedirectNum;
        $totalPartRedirectNum = $firePartRedirectNum + $productPartRedirectNum;
        $totalAllRedirectNum = $fireAllRedirectNum + $productAllRedirectNum;

        $fireData = array($fireAllRedirectNum,$firePartRedirectNum,$fireNoRedirectNum);
        $productData = array($productAllRedirectNum,$productPartRedirectNum,$productNoRedirectNum);
        $allData = array($totalAllRedirectNum,$totalPartRedirectNum,$totalNoRedirectNum);
        

        /*消防整改饼图*/
        $legend = array('已经整改','部分整改','未整改');
	    $legend = iconv_arr($legend);
        $fireDataMax = max($fireData);
        if($fireDataMax==0) {
        	$returnData['fireRedirectPie'] = array('path'=>'./storage/word_static_images/small_zero.png','width'=>272,'height'=>152);
        } else {
        	$graph_pie_fire = new \PieGraph(280,160);  
	        $graph_pie_fire->SetShadow();  
	        $theme_class= new \AquaTheme();
			$graph_pie_fire->SetTheme($theme_class);
	        
	        $pieplot = new \PiePlot3D($fireData);  //创建PiePlot3D对象  
	        $pieplot->SetSize(0.28);//设置饼图大小
	        $pieplot->SetCenter(0.5, 0.5); //设置饼图中心的位置  
	        $pieplot->SetLegends(iconv_arr($legend)); //设置图例  
	        $graph_pie_fire->legend->SetFont(FF_SIMSUN,FS_BOLD);  
	          
	        $graph_pie_fire->Add($pieplot);

	        $pie_fire_imgname=rand(1000,10000).time().'_firepie.jpg';
	        $fileDirectory = 'storage/word_static_images/'.date('Ymd');
	        File::isDirectory($fileDirectory) or File::makeDirectory($fileDirectory);
	        $pie_fire_img = $fileDirectory.'/'.$pie_fire_imgname;
	        // Display the graph
	        try{
	        	$graph_pie_fire->Stroke($pie_fire_img);
	        	$returnData['fireRedirectPie'] = array('path'=>'./'.$pie_fire_img,'width'=>272,'height'=>152);
	        } catch(Exception $e){
	        	$returnData['fireRedirectPie'] = array();
	        } 
        }
        

        /*生产整改饼图*/
        $productDataMax = max($productData);
        if($productDataMax==0) {
        	$returnData['productRedirectPie'] = array('path'=>'./storage/word_static_images/small_zero.png','width'=>272,'height'=>152);
        } else {
        	$graph_pie_product = new \PieGraph(280,160);  
	        $graph_pie_product->SetShadow();  
	        $theme_class= new \AquaTheme();
			$graph_pie_product->SetTheme($theme_class);
	       
	        $pieplot_product = new \PiePlot3D($productData);  //创建PiePlot3D对象  
	        $pieplot_product->SetSize(0.28);//设置饼图大小
	        $pieplot_product->SetCenter(0.5, 0.5); //设置饼图中心的位置  
	        $pieplot_product->SetLegends(iconv_arr($legend)); //设置图例  
	        $graph_pie_product->legend->SetFont(FF_SIMSUN,FS_BOLD);  
	          
	        $graph_pie_product->Add($pieplot_product);  

	        $pie_product_imgname=rand(1000,10000).time().'_fireproduct.jpg';
	        $fileDirectory = 'storage/word_static_images/'.date('Ymd');
	        File::isDirectory($fileDirectory) or File::makeDirectory($fileDirectory);
	        $pie_product_img = $fileDirectory.'/'.$pie_product_imgname;
	        // Display the graph
	        try{
	        	$graph_pie_product->Stroke($pie_product_img);
	        	$returnData['productRedirectPie'] = array('path'=>'./'.$pie_product_img,'width'=>272,'height'=>152);
	        } catch(Exception $e){
	        	$returnData['productRedirectPie'] = array();
	        } 
        }
       
        /*所有整改饼图*/
        $allDataMax = max($allData);
        if($allDataMax==0) {
        	$returnData['allRedirectPie'] = array('path'=>'./storage/word_static_images/all_zero.png','width'=>467,'height'=>227);
        } else {
        	$graph_pie_all = new \PieGraph(480,240);  
	        $graph_pie_all->SetShadow(); 
	        $theme_class= new \AquaTheme();
			$graph_pie_all->SetTheme($theme_class); 
	       
	        $pieplot_all = new \PiePlot3D($allData);  //创建PiePlot3D对象 
	        $pieplot_all->SetSize(0.34);//设置饼图大小 
	        $pieplot_all->SetCenter(0.5, 0.5); //设置饼图中心的位置  
	        $pieplot_all->SetLegends(iconv_arr($legend)); //设置图例  
	        $graph_pie_all->legend->SetFont(FF_SIMSUN,FS_BOLD);  
	          
	        $graph_pie_all->Add($pieplot_all); 

	        $pie_all_imgname=rand(1000,10000).time().'_fireall.jpg';
	        $fileDirectory = 'storage/word_static_images/'.date('Ymd');
	        File::isDirectory($fileDirectory) or File::makeDirectory($fileDirectory);
	        $pie_all_img = $fileDirectory.'/'.$pie_all_imgname;
	        // Display the graph
	        try{
	        	$graph_pie_all->Stroke($pie_all_img);
	        	$returnData['allRedirectPie'] = array('path'=>'./'.$pie_all_img,'width'=>467,'height'=>227);
	        } catch(Exception $e){
	        	$returnData['allRedirectPie'] = array();
	        } 
        }

        return $returnData;
	}
}